/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.etop.ondoc.util;

import com.etop.ondoc.beans.Category;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

/**
 *
 * @author jansing
 * lz_jansing@163.com
 */
public class CommonsUtil {

    /**
     * 获取某个分类下的所有叶子分类
     * @param cate 
     * @return 
     */
    public static Set<Category> getAllSubCategorys(Category cate){
        Set<Category> cateSet = new HashSet<>();
        if(cate.getCateSet().isEmpty()){
            return cateSet;
        }
        if(getAllSubCategorys(cate.getCateSet().iterator().next()).isEmpty()){
            cateSet.addAll(cate.getCateSet());
        }else {
            Iterator<Category> iterator = cate.getCateSet().iterator();
            while(iterator.hasNext()){
                cateSet.addAll(getAllSubCategorys(iterator.next()));
            }
        }
        return cateSet;
    }
}
